package sk.vrto.web.presenters;

import sk.vrto.domain.Email;
import sk.vrto.service.dao.EmailRepository;
import sk.vrto.web.base.Presenter;
import sk.vrto.web.events.EmailRemoved;
import sk.vrto.web.events.UiEmailEvent;
import sk.vrto.web.views.EmailView;

public class EmailPresenter extends Presenter<EmailView> {

    private final EmailRepository emailRepository;

    /**
     * @param emailRepository Repository for accesing emails
     */
    public EmailPresenter(EmailRepository emailRepository) {
        this.emailRepository = emailRepository;
    }

    /**
     * Fires {@link UiEmailEvent.FwReAddWindowEvent}
     * @param email Email to forward
     */
    public void forward(Email email) {
        eventBus.post(new UiEmailEvent.FwReAddWindowEvent(email,
                UiEmailEvent.FwReAddWindowEvent.FwRe.FORWARD));
    }

    /**
     * Fires {@link UiEmailEvent.FwReAddWindowEvent}
     * @param email Email to reply to
     */
    public void reply(Email email) {
        eventBus.post(new UiEmailEvent.FwReAddWindowEvent(email,
                UiEmailEvent.FwReAddWindowEvent.FwRe.REPLY));
    }

    /**
     * Removes email from the repository and fires {@link EmailRemoved} event.
     * @param email Email to remove.
     */
    public void deleteMail(Email email) {
        emailRepository.delete(email);
        eventBus.post(new EmailRemoved(view));
    }
}
